package com.example.mvvm.api

import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

class RetrofitManager {


    //半生对象 静态
    companion object{
        //懒汉单例双重教研锁
        private var instance:RetrofitManager?=null
        fun getInstance():RetrofitManager{
            if (instance==null){
                synchronized(RetrofitManager::class.java){
                    if (instance==null){
                        instance=RetrofitManager()
                    }
                }

            }
            return instance!!
        }
    }
    private fun getRetrofit():Retrofit{
        val retrofit = Retrofit.Builder()
            .baseUrl("http://10.161.9.80:7012")
            .client(getOkhttpClient())
            .addConverterFactory(GsonConverterFactory.create())
            .build()
        return  retrofit

    }

   private fun getOkhttpClient():OkHttpClient{
       return OkHttpClient.Builder().build()
   }

    fun <T> create(service:Class<T>):T{
        return getRetrofit().create(service)
    }



}